home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-11 | 9.4 KB | 467 lines | [TEXT/CWIE] |
- // CEverythingDoc.cp -- Document methods
-
- #include "CEverythingDoc.h"
- #include "CEverythingData.h"
-
- #include "DDocData.h"
- #include "CButtons.h"
- #include "DDocData.h"
- #include "CCheckboxes.h"
- #include "DDocData.h"
- #include "CRadios.h"
- #include "DDocData.h"
- #include "CEditText.h"
- #include "DDocData.h"
- #include "CStuff.h"
- #include "DDocData.h"
- #include "CBars.h"
- #include "EverythingCmds.h"
- #include "CModalButtons.h"
- #include "CModalCheckboxes.h"
- #include "CModalRadios.h"
- #include "CModalText.h"
- #include "CModalStuff.h"
- #include "CModalBars.h"
-
- #include <LFile.h>
- #include <LPlaceHolder.h>
- #include <LPrintout.h>
- #include <LString.h>
- #include <LWindow.h>
- #include <TArrayIterator.h>
- #include <UWindows.h>
-
- const ResIDT prto_PrintView = 201;
- const ResIDT STRx_Untitled = 128;
-
- // ---------------------------------------------------------------------------
- // • CEverythingDoc
- // ---------------------------------------------------------------------------
-
- CEverythingDoc::CEverythingDoc(
- LCommander *inSuper)
- : LSingleDoc(inSuper)
- {
- mData = new CEverythingData();
- }
-
- // ---------------------------------------------------------------------------
- // • ~CEverythingDoc
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- CEverythingDoc::~CEverythingDoc()
- {
- // Delete all SubCommanders - copied from LCommander
- // This fixes a bug that existed in CW11 and prior.
- // It appears that the bug is fixed in CW Pro 1,
- // so this code probably is no longer needed.
- TArrayIterator<LCommander*> iterator(mSubCommanders, LArrayIterator::from_End);
- LCommander* theSub;
- while (iterator.Previous (theSub)) {
- mSubCommanders.RemoveItemsAt (1, iterator.GetCurrentIndex());
- delete theSub;
- }
- mWindow = nil;
-
- delete mData;
- }
-
- //----------
- void
- CEverythingDoc::newFile()
- {
- mData->NewData();
-
- MakeWindows();
-
- NameNewDoc(); // Set name of untitled window
- }
-
- //----------
- void
- CEverythingDoc::openFile(
- FSSpec *inFileSpec)
- {
- mData->OpenData (inFileSpec);
-
- MakeWindows();
-
- if (mWindow != nil) {
- mWindow->SetDescriptor (inFileSpec->name);
- }
- mIsSpecified = true;
- }
-
- // ---------------------------------------------------------------------------
- // • MakeWindows
- // ---------------------------------------------------------------------------
-
- void
- CEverythingDoc::MakeWindows()
- {
- DDocData* docData = mData->GetDocData ();
-
- mButtons = CButtons::CreateButtons(this, docData);
- mCheckboxes = CCheckboxes::CreateCheckboxes(this, docData);
- mRadios = CRadios::CreateRadios(this, docData);
- mEditText = CEditText::CreateEditText(this, docData);
- mStuff = CStuff::CreateStuff(this, docData);
- mBars = CBars::CreateBars(this, docData);
-
- mWindow = mButtons;
- }
-
- // ---------------------------------------------------------------------------
- // • NameNewDoc
- // ---------------------------------------------------------------------------
- // Name a new, untitled document window
- //
- // Untitled windows start with "untitled", then "untitled 1",
- // "untitled 2", etc. Old numbers are reused, so there won't be
- // gaps in the numbering.
- //
- // This routine uses a STR# resource to store the "untitled" string,
- // which can be localized to different languages. The first string
- // is "untitled" and the second is "untitled " (trailing space),
- // which is used when appending a number to the name.
-
- void
- CEverythingDoc::NameNewDoc()
- {
- // Start with the default name("untitled")
- Str255 name;
- ::GetIndString(name, STRx_Untitled, 1);
-
- long num = 0;
- while (UWindows::FindNamedWindow(name) != nil) {
-
- // An existing window has the current name
- // Increment counter and try again
-
- ::GetIndString(name, STRx_Untitled, 2);
- num++;
- Str15 numStr;
- ::NumToString(num, numStr);
- LString::AppendPStr(name, numStr);
- }
-
- mWindow->SetDescriptor(name); // Finally, set window title
- }
- // ---------------------------------------------------------------------------
- // • IsModified
- // ---------------------------------------------------------------------------
- // Return whether the Document has changed since the last save
-
- Boolean
- CEverythingDoc::IsModified()
- {
- mIsModified = mData->IsDirty();
-
- return mIsModified;
- }
-
- // ---------------------------------------------------------------------------
- // • DoAESave
- // ---------------------------------------------------------------------------
- // Save Document in the specified file with the specified file type
- //
- // If file type is fileType_Default, use the normal file type for
- // this document
-
- void
- CEverythingDoc::DoAESave(
- FSSpec &inFileSpec,
- OSType inFileType)
- {
- mData->DoSaveAs(&inFileSpec); // Write out data
- // Change window name
- mWindow->SetDescriptor(inFileSpec.name);
- }
-
- //----------
- void
- CEverythingDoc::DoSave()
- {
- mData->DoSave();
- }
-
- //----------
- void
- CEverythingDoc::DoRevert()
- {
- mData->DoRevert();
- }
-
- // ---------------------------------------------------------------------------
- // • DoPrint
- // ---------------------------------------------------------------------------
- // Print the contents of the Document
-
- void
- CEverythingDoc::DoPrint()
- {
- LPrintout *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
- LPlaceHolder *textPlace = (LPlaceHolder *)
- thePrintout->FindPaneByID('TBox');
- //! textPlace->InstallOccupant(mTextView, atNone);
-
-
- thePrintout->DoPrintJob();
- delete thePrintout;
- }
-
- //----------
- void CEverythingDoc::DoModalButtons ()
- {
- CModalButtons* dialog = CModalButtons::CreateModalButtons (this, cmdModalButtons);
- }
-
- //----------
- void CEverythingDoc::FinishModalButtons (
- void* ioParam)
- {
- CModalButtons* dialog = (CModalButtons *)ioParam;
-
-
- // post-invoke code
-
- delete dialog;
- }
-
- //----------
- void CEverythingDoc::DoModalCheckboxes ()
- {
- DModalCheckboxesData* data = new DModalCheckboxesData;
-
-
- // pre-invoke code
-
- CModalCheckboxes* dialog = CModalCheckboxes::CreateModalCheckboxes (this, cmdModalCheckboxes, data);
- }
-
- //----------
- void CEverythingDoc::FinishModalCheckboxes (
- void* ioParam)
- {
- CModalCheckboxes* dialog = (CModalCheckboxes *)ioParam;
- DModalCheckboxesData* data = dialog->GetData ();
-
-
- // post-invoke code
-
- delete dialog;
- }
-
- //----------
- void CEverythingDoc::DoModalRadios ()
- {
- DModalRadiosData* data = new DModalRadiosData;
-
-
- // pre-invoke code
-
- CModalRadios* dialog = CModalRadios::CreateModalRadios (this, cmdModalRadios, data);
- }
-
- //----------
- void CEverythingDoc::FinishModalRadios (
- void* ioParam)
- {
- CModalRadios* dialog = (CModalRadios *)ioParam;
- DModalRadiosData* data = dialog->GetData ();
-
-
- // post-invoke code
-
- delete dialog;
- }
-
- //----------
- void CEverythingDoc::DoModalText ()
- {
- DModalTextData* data = new DModalTextData;
-
-
- // pre-invoke code
-
- CModalText* dialog = CModalText::CreateModalText (this, cmdModalText, data);
- }
-
- //----------
- void CEverythingDoc::FinishModalText (
- void* ioParam)
- {
- CModalText* dialog = (CModalText *)ioParam;
- DModalTextData* data = dialog->GetData ();
-
-
- // post-invoke code
-
- delete dialog;
- }
-
- //----------
- void CEverythingDoc::DoModalStuff ()
- {
- DModalStuffData* data = new DModalStuffData;
-
-
- // pre-invoke code
-
- CModalStuff* dialog = CModalStuff::CreateModalStuff (this, cmdModalStuff, data);
- }
-
- //----------
- void CEverythingDoc::FinishModalStuff (
- void* ioParam)
- {
- CModalStuff* dialog = (CModalStuff *)ioParam;
- DModalStuffData* data = dialog->GetData ();
-
-
- // post-invoke code
-
- delete dialog;
- }
-
- //----------
- void CEverythingDoc::DoModalMoreStuff ()
- {
- DModalBarsData* data = new DModalBarsData;
-
-
- // pre-invoke code
-
- CModalBars* dialog = CModalBars::CreateModalBars (this, cmdModalMoreStuff, data);
- }
-
- //----------
- void CEverythingDoc::FinishModalMoreStuff (
- void* ioParam)
- {
- CModalBars* dialog = (CModalBars *)ioParam;
- DModalBarsData* data = dialog->GetData ();
-
-
- // post-invoke code
-
- delete dialog;
- }
-
- //----------
- Boolean
- CEverythingDoc::ObeyCommand(
- CommandT inCommand,
- void* ioParam)
- {
- Boolean cmdHandled = true;
-
- if (inCommand < 0) {
- // modal dialog has finished
-
- switch (-inCommand) {
- case cmdModalButtons:
- FinishModalButtons (ioParam);
- break;
-
- case cmdModalCheckboxes:
- FinishModalCheckboxes (ioParam);
- break;
-
- case cmdModalRadios:
- FinishModalRadios (ioParam);
- break;
-
- case cmdModalText:
- FinishModalText (ioParam);
- break;
-
- case cmdModalStuff:
- FinishModalStuff (ioParam);
- break;
-
- case cmdModalMoreStuff:
- FinishModalMoreStuff (ioParam);
- break;
-
- }
-
- } else {
- switch (inCommand) {
-
- case cmdModalButtons:
- DoModalButtons ();
- break;
-
- case cmdModalCheckboxes:
- DoModalCheckboxes ();
- break;
-
- case cmdModalRadios:
- DoModalRadios ();
- break;
-
- case cmdModalText:
- DoModalText ();
- break;
-
- case cmdModalStuff:
- DoModalStuff ();
- break;
-
- case cmdModalMoreStuff:
- DoModalMoreStuff ();
- break;
-
- default:
- cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
- break;
- }
- }
-
- return cmdHandled;
- }
-
- //----------
- void
- CEverythingDoc::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle
-
- case cmdModalButtons:
- outEnabled = true;
- break;
- case cmdModalCheckboxes:
- outEnabled = true;
- break;
- case cmdModalRadios:
- outEnabled = true;
- break;
- case cmdModalText:
- outEnabled = true;
- break;
- case cmdModalStuff:
- outEnabled = true;
- break;
- case cmdModalMoreStuff:
- outEnabled = true;
- break;
-
- default:
- LSingleDoc::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-